package com.example.springboot.controller;
import com.example.springboot.common.Result;
import com.example.springboot.entity.Order;
import com.example.springboot.mapper.OrderMapper;
import com.example.springboot.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private OrderMapper orderMapper;
    @Autowired
    private OrderService orderService;
    //查询全部
    @GetMapping
    public Result findAll(){
        return Result.success(orderMapper.findAll());
    }
    //新增
    @PostMapping
    public Result create(@RequestBody Order order) throws Exception {
        return Result.success(orderService.create(order));
    }
    //删除
    @DeleteMapping("/{oid}")
    public Result deleteByOid(@PathVariable Long oid){
        return Result.success(orderMapper.deleteByOid(oid));
    }
    @DeleteMapping("/{did}")
    public Result deleteByDid(@PathVariable Long did){
        return Result.success(orderMapper.deleteByDid(did));
    }
    //查询
    @GetMapping("/findbyoid")
    public Result findByOid(@RequestParam Long oid){
        List<Order> one=orderMapper.findByOid(oid);
        return Result.success(one);
    }
    @GetMapping("/findbyname")
    public Result findByUname(@RequestParam String uname){
        List<Order> all=orderMapper.findByUname(uname);
        return Result.success(all);
    }
    @GetMapping("/findbydid")
    public Result findByDid(@RequestParam Long did){
        List<Order> all=orderMapper.findByDid(did);
        return Result.success(all);
    }
}
